
var app = require('express')();
var server = require('http').Server(app);
app.get('/',function(req,res){
    res.sendFile(__dirname,'/index.html'); // 只能是绝对地址
})

app.listen(3000);



var WebSocket = require('ws');
var wss = new WebSocket.Server({port:8080});
wss.on('connection',(ws) => {

    ws.on('message',(msg) => {
        console.log('server received:%s',msg);
    })

    setInterval(() => {
        ws.send('this is a message from server');
            
    }, 1000);
    
})


